package eraikikon;

import eraikikon.ResultSetTableModel;

import eraikikon.EI;

import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;

import eraikikon.*;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;

public class ArduradunGui extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JMenu jMenu = null;

	private JMenu jMenu1 = null;

	private JMenuItem jMenuItem = null;

	private JMenuItem jMenuItem1 = null;

	private JMenuBar jJMenuBar = null;

	private JMenuItem jMenuItem2 = null;

	private JMenuItem jMenuItem3 = null;

	private JMenuItem jMenuItem4 = null;

	private JMenuItem jMenuItem5 = null;

	private JMenu jMenu2 = null;
	private  JTable resultTable=null;
	private JMenuItem jMenuItem6 = null;
	
	private JTextField jTextField=null;
	
	private JLabel jLabel1;
	
	private AteKudeatzailea ateKud=new AteKudeatzailea();  //  @jve:decl-index=0:
	
	private IntzidentziaKud intzidentziaKud=new IntzidentziaKud();
	
	private ItisKud itisKud = new ItisKud();

	/**
	 * This is the default constructor
	 */
	private ResultSetTableModelD tableModel;

	private JMenuItem jMenuItem7 = null;

	private JMenuItem jMenuItem8 = null;
	/**
	 * Eraikitzailea: Arduradunak egin ditzaken 
	 *
	 */
	public ArduradunGui() {
		super();
		initialize();
		try {
			tableModel=new ResultSetTableModelD("com.mysql.jdbc.Driver","jdbc:mysql://localhost/eraikikon2","ikasle01","ikasle01","SELECT * FROM intzidentzia");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		resultTable= new JTable(tableModel);
	
		JScrollPane jScrollPane1= new JScrollPane(resultTable,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		jContentPane.add(jScrollPane1, BorderLayout.CENTER);
		Box box=Box.createHorizontalBox();
		jTextField =new JTextField();
		JLabel jLabel=new JLabel();
		jLabel1=new JLabel();
		jLabel1.setBackground(Color.gray);
		jLabel.setText("Eraikinean dagoien pertsona kopurua:");
		jLabel1.setText("ALARMA");
		box.add(jLabel);
		box.add(jTextField);
		box.add(jLabel1);
		jContentPane.add(box, BorderLayout.SOUTH);
		
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(628, 177);
		this.setLocation(new Point(400, 200));
		this.setJMenuBar(getJJMenuBar());
		this.setContentPane(getJContentPane());
		this.setTitle("Arduradunaren kontsultak");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
		}
		return jContentPane;
	}

	/**
	 * This method initializes jMenu	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu() {
		if (jMenu == null) {
			jMenu = new JMenu();
			jMenu.setText("Alarma");
			jMenu.add(getJMenuItem());
			jMenu.add(getJMenuItem1());
		}
		return jMenu;
	}

	/**
	 * This method initializes jMenu1	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu1() {
		if (jMenu1 == null) {
			jMenu1 = new JMenu();
			jMenu1.setText("Txartela");
			jMenu1.add(getJMenuItem4());
			jMenu1.add(getJMenuItem5());
		}
		return jMenu1;
	}

	/**
	 * This method initializes jMenuItem	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem() {
		if (jMenuItem == null) {
			jMenuItem = new JMenuItem();
			jMenuItem.setText("Alarma aktibatu");
			jMenuItem.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Calendar gaur = new GregorianCalendar();
					gaur.setTime(new Date());
					gaur.add(Calendar.MONTH, +1);
					String data= gaur.get(Calendar.YEAR)+"-"+gaur.get(Calendar.MONTH)+"-"+gaur.get(Calendar.DATE)+" "+gaur.get(Calendar.HOUR)+":"+gaur.get(Calendar.MINUTE)+":"+gaur.get(Calendar.SECOND);
					jTextField.setText(itisKud.zenbatEraikinean().toString());
					jLabel1.setText("ALARMA GAITUA");
					jLabel1.setForeground(Color.RED);
					intzidentziaKud.intzidentziasortu(data, "larria", "Alarma", "Alarma gaitu da",0,0,0,'e');
					ateKud.ateakIreki();
				}
			});
		}
		return jMenuItem;
	}

	/**
	 * This method initializes jMenuItem1	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem1() {
		if (jMenuItem1 == null) {
			jMenuItem1 = new JMenuItem();
			jMenuItem1.setText("Alarma desgaitu");
			jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 // TODO Auto-generated Event stub actionPerformed()
					jLabel1.setText("ALARMA");
					jLabel1.setForeground(Color.gray);
					ateKud.ateakItxi();
				}
			});
		}
		return jMenuItem1;
	}

	/**
	 * This method initializes jJMenuBar	
	 * 	
	 * @return javax.swing.JMenuBar	
	 */
	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.add(getJMenu());
			jJMenuBar.add(getJMenu1());
			jJMenuBar.add(getJMenu2());
		}
		return jJMenuBar;
	}

	/**
	 * This method initializes jMenuItem4	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem4() {
		if (jMenuItem4 == null) {
			jMenuItem4 = new JMenuItem();
			jMenuItem4.setText("Txartela gaitu");
			jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 // TODO Auto-generated Event stub actionPerformed()
					TxartelaGaitu tg = new TxartelaGaitu();
					tg.setVisible(true);
					
				}
			});
		}
		return jMenuItem4;
	}

	/**
	 * This method initializes jMenuItem5	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem5() {
		if (jMenuItem5 == null) {
			jMenuItem5 = new JMenuItem();
			jMenuItem5.setText("Txartela desgaitu");
			jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 // TODO Auto-generated Event stub actionPerformed()
					TxartelaDesgaitu td = new TxartelaDesgaitu();
					td.setVisible(true);
					
				}
			});
		}
		return jMenuItem5;
	}

	/**
	 * This method initializes jMenu2	
	 * 	
	 * @return javax.swing.JMenu	
	 */
	private JMenu getJMenu2() {
		if (jMenu2 == null) {
			jMenu2 = new JMenu();
			jMenu2.setText("Ekintzak");
			jMenu2.add(getJMenuItem6());
			jMenu2.add(getJMenuItem7());
			jMenu2.add(getJMenuItem8());
		}
		return jMenu2;
	}

	/**
	 * This method initializes jMenuItem6	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem6() {
		if (jMenuItem6 == null) {
			jMenuItem6 = new JMenuItem();
			jMenuItem6.setText("Irakasle gatazkatsuenak");
			jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					EI ei=new EI();
					ei.setVisible(true);
					ei.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				}
			});
		}
		
		return jMenuItem6;
	}

	/**
	 * This method initializes jMenuItem7	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem7() {
		if (jMenuItem7 == null) {
			jMenuItem7 = new JMenuItem();
			jMenuItem7.setText("Erabiltzaileak kontsultatu");
			jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 // TODO Auto-generated Event stub actionPerformed()
					ErabiltzaileakBistaratu eb = new ErabiltzaileakBistaratu();
					eb.setVisible(true);
				}
			});
			
		}
		return jMenuItem7;
	}
	/**
	 * This method initializes jMenuItem8	
	 * 	
	 * @return javax.swing.JMenuItem	
	 */
	private JMenuItem getJMenuItem8() {
		if (jMenuItem8 == null) {
			jMenuItem8 = new JMenuItem();
			jMenuItem8.setText("Sarbide eskaerak kontsultatu");
			jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				SarbideakBistaratu sb= new SarbideakBistaratu();
				sb.setVisible(true);
				}
			});
		}
		return jMenuItem8;
	}

	public static void main(String [] args){
		ArduradunGui arduradunGui=new ArduradunGui();
		arduradunGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		arduradunGui.setVisible(true);
	}
}  //  @jve:decl-index=0:visual-constraint="10,10"
